package cn.yuhh.api.manage.api;

import cn.yuhh.api.exception.ApiException;
import cn.yuhh.api.helper.ApiResponse;
import cn.yuhh.api.service.AbstractApiService;
import cn.yuhh.core.domain.User;
import com.magic.spring.mongo.Mongo;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author ysw
 * @create 2020-03-01-12:00
 * @descreption 创建用户
 **/
@Component("userCreate1.0")
public class UserCreateService extends AbstractApiService {
    @Override
    public Map service(Map request) {
        if(Mongo.buildMongo().eq("tel", string(request, "tel")).count(User.class)>0){
            throw new ApiException("电话号码已存在");
        }
        User user = map2bean(User.class, request);
        Mongo.buildMongo().insert(user);
        return ApiResponse.success();
    }

}
